// ============================== 导入依赖 ============================== //

// ============================== 导出计算属性 ============================== //

export default {
  /**
   * 初始化完成 (可覆盖，依赖模块完成后，再调用 MAIN_START)
   */
  inited: (state) => state.readyBase && state.group.readySelect && state.module.readySelect,

  /**
   * 自定义计算属性 (可覆盖)
   */
  GETTER: ({ group, module, menu, one }) => {
    const groups = group.select.filter((group) => module.select.some((minor) => minor.groupId === group.id))
    const modules = module.select.filter((minor) => groups.some((group) => minor.groupId === group.id))
    const menus = menu.select.filter((menu) => modules.some((minor) => minor.id === menu.moduleId))
    const catalogues = menus.map(({ catalogue }) => catalogue)

    return {
      grayedCatalogue: catalogues.filter((catalogue) => catalogue !== one.oldCatalogue),

      groupModule: groups.map(({ id, name }) => {
        const matched = modules.filter((module) => module.groupId === id)
        const children = matched.map(({ id, name }) => [[], id, name])
        return [children, id, name]
      }),
    }
  },
}
